<template>
  <view>
    <u-navbar :background="{ background: '' }" back-icon-color="#222222" title-color="#222222" :is-back="false" :border-bottom="false"></u-navbar>
    <view class="" style="text-align: center; margin-top: 46rpx">
      <image src="https://wenzhen.fuerle168.com/static/logo.png" mode="" style="width: 180rpx; height: 180rpx; border-radius: 50%"></image>
      <view class="" style="font-size: #222; font-size: 36rpx; font-weight: bold">问诊系统</view>
    </view>
    <!-- <view class="" style="display: flex; align-items: center; padding-left: 116rpx; padding-top: 65rpx; padding-bottom: 10rpx">
      <image src="../../static/login/phone.png" mode="" style="width: 30rpx; height: 30rpx"></image>
      <view class="" style="font-size: 26rpx; padding-left: 11rpx">账号</view>
    </view>
    <view class="">
      <input
        type="text"
        style="margin: 15rpx 85rpx; box-shadow: 0px 0px 20rpx 0px rgba(0, 0, 0, 0.08); border-radius: 41rpx; height: 82rpx; font-size: 26rpx; color: #aaaaaa; padding-left: 63rpx"
        placeholder="请输入手机号"
        v-model="mobile"
      />
    </view>
    <view class="" style="display: flex; align-items: center; padding-left: 116rpx; padding-top: 40rpx; padding-bottom: 10rpx">
      <image src="../../static/login/yzm.png" mode="" style="width: 30rpx; height: 30rpx"></image>
      <view class="" style="font-size: 26rpx; padding-left: 11rpx">验证码</view>
    </view>
    <view class="" style="display: flex; align-items: center; margin: 12rpx 60rpx 73rpx 85rpx; justify-content: space-between">
      <input
        type="text"
        style="box-shadow: 0px 0px 20rpx 0px rgba(0, 0, 0, 0.08); border-radius: 41rpx; height: 82rpx; font-size: 26rpx; color: #aaaaaa; padding-left: 63rpx; width: 392rpx"
        placeholder="请输入验证码"
        v-model="code"
      />
      <view class="" style="font-size: 26rpx; color: #19a2ff" @tap="yzm">
        {{ BtnText }}
      </view>
    </view> -->
    <!--  <view class="btn" style="margin-top: 100rpx" @tap="login2">登录</view> -->
    <button class="btn" open-type="getPhoneNumber" style="margin-top: 100rpx" @getphonenumber="login2">登录</button>
    <view class="" style="display: flex; align-items: center; justify-content: center; margin-top: 25rpx">
      <radio :checked="radio" style="transform: scale(0.7)" color="#19A2FF" @tap="radio = !radio"></radio>
      <view class="" style="font-size: 24rpx; color: #666666">
        登录即代表同意
        <text style="color: #19a2ff" @tap="get(3)">《用户协议》</text>
        <text style="color: #19a2ff" @tap="get(1)">《隐私政策》</text>
      </view>
    </view>

    <!-- <view class="" style="text-align: center; margin-top: 157rpx" @tap="autologin('weixin')">
      <image src="../../static/login/wx.png" mode="" style="width: 76rpx; height: 76rpx"></image>
      <view class="" style="font-size: 24rpx; color: #666666">微信登录</view>
    </view> -->

    <u-toast ref="uToast" />
  </view>
</template>

<script>
// const openinstall = uni.requireNativePlugin('openinstall-plugin');

export default {
  data() {
    return {
      radio: false,
      BtnText: '获取验证码',
      mobile: '',
      code: '',
      second: 60,
      result: '',
      doctor_id: null,
      userSig: ''
    };
  },
  methods: {
    // 快捷登录
    login2(e) {
      if (!this.radio) {
        return uni.showToast({
          title: '请先阅读勾选用户协议和隐私政策',
          icon: 'none'
        });
      }
      console.log(e.detail.code, '手机号的code');
      uni.login({
        success: (res) => {
          console.log(res, 'login的code');
          this.api({
            url: 'api/user/weChatMiniLogin  ',
            method: 'post',
            data: {
              code: res.code,
              mobile_code: e.detail.code
            }
          }).then(async (res2) => {
            console.log('登录的结果', res2);
            uni.setStorageSync('user_info', res2.data);
            this.api({
              url: '/api/chat/getSign',
              method: 'post'
            }).then((data) => {
              uni.setStorageSync('usersig', data.data);
              this.util.loginim(data.data);
              this.$refs.uToast.show({
                title: '登录成功',
                type: 'success'
              });

              setTimeout(() => {
                uni.reLaunch({
                  url: '/pages/index/index'
                });
              }, 1000);
            });
          });
        }
      });
    },
    get(e) {
      uni.navigateTo({
        url: '/user/detail/detail?type=' + e
      });
    },
    login() {
      // openinstall.init();
      if (!this.radio) {
        uni.showToast({
          title: '请先阅读勾选用户协议和隐私政策',
          icon: 'none'
        });
      } else {
        let that = this;
        this.api({
          url: 'api/user/mobilelogin',
          method: 'post',
          data: {
            mobile: this.mobile,
            captcha: this.code
          }
        }).then((data) => {
          uni.setStorageSync('user_info', data.data.userinfo);
          // this.api({
          // 	url: '/api/chat/getSign',
          // 	method: 'post',

          // }).then(res => {
          // 	uni.setStorageSync('usersig', res.data)
          // 	this.util.loginim(res.data)
          this.$refs.uToast.show({
            title: '登录成功',
            type: 'success'
          });
          setTimeout(() => {
            uni.reLaunch({
              url: '/pages/index/index'
            });
          }, 1000);
          return false;
          // openinstall.getInstall(8, function (result) {
          //   if (result.bindData) {
          //     let str = JSON.stringify(result.bindData);
          //     var arrayList = str.split(':');
          //     let uid = arrayList[1];
          //     that.doctor_id = uid
          //       .replace(/\s/g, '')
          //       .replace(/[^a-zA-Z0-9]/g, '')
          //       .toLowerCase();
          //     if (that.doctor_id) {
          //       setTimeout(() => {
          //         uni.reLaunch({
          //           url: '/pages/index/doctor?id=' + that.doctor_id
          //         });
          //       }, 1000);
          //     } else {
          //       setTimeout(() => {
          //         uni.reLaunch({
          //           url: '/pages/index/index'
          //         });
          //       }, 1000);
          //     }
          //   } else {
          //     setTimeout(() => {
          //       uni.reLaunch({
          //         url: '/pages/index/index'
          //       });
          //     }, 1000);
          //   }
          // });
        });
      }
    },
    yos() {
      let e = '"9"}"';
      console.log(str);
      // let onestr = e.replace('\','/');
      // let twostr = onestr.replace('"','');
      //  this.doctor_id = onestr.replace('}','');
    },
    yzm() {
      if (this.mobile.length != 11) {
        uni.showToast({
          icon: 'none',
          title: '手机号不正确'
        });
        return;
      }
      if (this.BtnText == '获取验证码') {
        this.fasong();

        var interval = setInterval(() => {
          this.BtnText = this.second + 's 重新获取';

          this.second--; //在data中定义second倒计时的时间

          if (this.second == 0) {
            clearInterval(interval);

            this.second = 60;

            this.BtnText = '获取验证码';
          }
        }, 1000);
      }
    },
    fasong() {
      this.api({
        url: 'api/sms/send',
        method: 'post',
        data: {
          mobile: this.mobile,
          event: 'mobilelogin'
        }
      }).then((data) => {
        uni.showToast({
          title: data.msg,
          icon: 'none'
        });
      });
    }
  },
  onShow() {}
};
</script>

<style>
.btn {
  margin: 0 115rpx;
  height: 82rpx;
  background: linear-gradient(0deg, #1a9eff 0%, #0fb8ff 100%);
  border-radius: 41rpx;
  font-size: 30rpx;
  color: #fff;
  line-height: 82rpx;
  text-align: center;
}
</style>
